package com.jeady.timetodo

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import com.jeady.timetodo.activities.task.TaskType
import com.jeady.timetodo.activities.light.LightController
import com.jeady.timetodo.activities.lock.ScreenController
import com.jeady.timetodo.activities.vibrate.VibrateController
import com.jeady.timetodo.utils.TimeToDoAction

class TaskReceiver : BroadcastReceiver() {
    private val TAG: String = "[TaskReceive]"
    override fun onReceive(context: Context, intent: Intent) {
        Log.d(TAG, "onReceive: ${intent.action}")
        when(intent.action){
            TimeToDoAction.ACTION_EXECUTE_TASK.name->{
                Log.d(TAG, "onReceive: action ${intent.getStringExtra("state")}")
                when(intent.getStringExtra("state")){
                    TaskType.LIGHT_ON.name-> LightController.open(context)
                    TaskType.LIGHT_OFF.name-> LightController.close(context)
                    TaskType.LOCK_SCREEN.name-> ScreenController.getInstance(context)?.lockPhone(context)
                    TaskType.VIBRATE.name-> VibrateController.vibrate(context)
                    TaskType.STOP_VIBRATE.name-> VibrateController.stopVibrate(context)
                }
            }
        }
    }
}